package com.ldc.security.model;

import com.ldc.common.constants.ConstantsCodeStatus;
import com.ldc.model.SysUserBean;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
 * @auther liudc
 * @since 2022/11/6
 */

@NoArgsConstructor
@Data
public class LoginUserBean implements UserDetails {
    private SysUserBean userBean;
    // 授予的权限
    private List<GrantedAuthority> authorities;

    public LoginUserBean(SysUserBean userBean, List<GrantedAuthority> authorities) {
        this.userBean = userBean;
        this.authorities = authorities;
    }

    @Override
    public List<GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return userBean.getPassWord();
    }

    @Override
    public String getUsername() {
        return userBean.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return Objects.equals(ConstantsCodeStatus.IS_AVAILABLE, userBean.getStatus());
    }

    public SysUserBean getUserBean() {
        return userBean;
    }
}
